import request from '@/utils/request'

// 获取分类
export function getCateList() {
  
  return request({
    'url': '/home/getAllCategories',
  
    'method': 'Post',
  })
}
// 获取品类下商品
export function getProductList(cateGoryId, priceMin = null, priceMax = null, sortType = 0) {
  // 构造 URL 参数
  let url = `/home/getProductList/${cateGoryId}/${sortType}`;

  // 设置查询参数
  const params = {};
  if (priceMin !== null) params.priceMin = priceMin;
  if (priceMax !== null) params.priceMax = priceMax;

  return request({
    url: url, 
    method: 'get',
    params: params, // 添加查询参数到请求中
  });
}

// 插入商品
export function createPruduct(data) {
  
  return request({
    'url': '/home/addProduct',

    'method': 'Post',
	 data
  })
}
//模糊查询
export function searchProduct(params) {
  return request({
    url: '/home/search',
    method: 'get',
    data: params, // 传递键值对形式的查询参数
  });
}

export function deleteProduct(productId) {
  return request({
    url: `/home/deleteProduct/${productId}`,
    method: 'delete',
   
  });
}

export function updateProduct(data) {
  return request({
    url: `/home/updateProduct`,
    method: 'put',
   data
  });
}

export function deleteImage(imageId) {
  return request({
    url: `/home/deleteImage/${imageId}`,
    method: 'delete',

  });
}